
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>求阶乘</title>
		<script>
			
			function fun () {
				var text = document.getElementById("num");
				var span = document.getElementById("result");
				var val = text.value;
				if(val =='' || isNaN(val)){
									 span.innerHTML = "请输入数字";
				}else{
					var sum = 1;
					for(var i = val;i;i--){
						sum*=i;
					}
					span.innerHTML = sum;
				}
				
			}
			 
		</script>
	</head>
	<body>
		<p>
			<input type="text" id="num"/>
			<input type="button" value="阶乘" onclick="fun()" />
		</p>
		<p>
			<span id='result'></span>
		</p>
	</body>
</html>